<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head >
    <meta charset="UTF-8">
    <title>注册页面</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="alternate icon" type="image/png" href="../../static/AmazeUI/assets/i/favicon.png">
    <link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.css"/>

    <style>
        .header {
            text-align: center;
        }
        .header h1 {
            font-size: 200%;
            color: #333;
            margin-top: 30px;
        }
        .header p {
            font-size: 14px;
        }
    </style>
</head>
<body>
<div class="header">
    <div class="am-g">
        <h1>我的博客</h1>
        <p>Integrated Development Environment<br/>为梦想而生</p>
    </div>
    <hr />
</div>
<div class="am-g">
    <div class="am-u-lg-6 am-u-md-8 am-u-sm-centered">
        <form method="post" class="am-form">
            <label for="username">用户名:</label>
            <input type="text" name="username" id="username" value="">
            <br>
            <label for="password">密码:</label>
            <input type="password" name="password" id="password" value="">
            <br>
            <label for="email">邮箱:</label>
            <input type="email" name="email" id="email" value="">
            <br>
            <label for="remember-me">
                <input id="remember-me" type="checkbox">
                记住密码
            </label>
            <br />
            <div class="am-cf">
                <input type="button" id="register_btn" value="注 册" class="am-btn am-btn-primary am-btn-sm am-fl">
                <input type="button" id="login_btn" value="返回登录" class="am-btn am-btn-default am-btn-sm am-fr">
            </div>
        </form>
        <hr>
        <p>© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </div>
</div>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>

<script>
    $(function () {
        /**
         * 校验用户名是否存在，若存在不可注册，请直接登录
         */
        $("#username").change(function () {
            var username = {
                "username": $("#username").val(),
            }
            $.ajax({
                url: "/admin/checkUsername",
                data: username,
                type: "GET",
                dataType:"json",
                success: function (data) {
                    //alert(data.status);
                    if (data.status==-1) {
                        alert("用户名已存在，请直接登录");
                        return false;
                    }
                }
            });
        });

        /**
         * 校验邮箱是否重复
         */
        $("#email").change(function () {
            var email = {
                "email": $("#email").val(),
            }
            $.ajax({
                url: "/admin/checkEmail",
                data: email,
                type: "GET",
                dataType:"json",
                success: function (data) {
                    //alert(data.status);
                    if (data.status==-1) {
                        alert("邮箱已经存在,请更换");
                        return false;
                    }
                }
            });
        });

        /**
         * 注册用户
         */
        $("#register_btn").click(function () {
            var data1 = {
                "username": $("#username").val(),
                "password": $("#password").val(),
                "email": $("#email").val()
            }
            $.ajax({
                url: "/admin/register",
                data: data1,
                type: "GET",
                dataType:"json",
                success: function (data) {
                    //alert(data.status);
                    if (data.status==200) {
                        alert("注册成功");
                        //跳转到登录页面
                        window.location.href = '/admin/';
                    }
                }
            });
        });

        $("#login_btn").click(function () {
            //跳转到登录页面
            window.location.href = '/admin/';
        });
    });
</script>
</body>
</html>
